package com.cskaoyan.kpi.fsg;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ClassName FSGMapper
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/17 21:26
 * @Version V1.0
 **/
public class FSGMapper extends Mapper<Object, Text, Text, IntWritable> {

    private IntWritable one = new IntWritable(1);

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        //106.87.2.229---中国:重庆市:未知---2022-01-14 08:01:53---http://115.29.141.32:8085/#/mall/show/goodsList/190/all---firefox
        String line = value.toString();
        String[] parts = line.split("---");

        //获取到时间
        String date = parts[2].split(" ")[0];
        //假设我们要寻找的地址是这种模式http://115.29.141.32:8085/#/mall/goods/475
        ///mall/goods/xxx这种模式
        String url = parts[3];
        //如果页面中不包含这个字符，那么不是我们需要统计的数据
        if(!url.contains("/mall/goods/")){
            return;
        }
        int index = url.lastIndexOf("/");
        String goodsId = url.substring(index + 1);
        context.write(new Text(date + ":" + goodsId), one);
    }
}
